package com.zxmc.init;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.zxmc.common.utils.BloomFilterUtil;
import com.zxmc.server.service.ChapterService;
import com.zxmc.server.service.NovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.List;

@Component
public class BloomFilterInitializer implements CommandLineRunner {

    @Autowired
    private BloomFilterUtil bloomFilterUtil;

    @Autowired
    private NovelService novelService;

    @Autowired
    private ChapterService chapterService;
    @Override
    public void run(String... args) throws Exception {
        // 从数据库或其他数据源获取初始数据
        List<Integer> NovelIds = novelService.listAllIds();
        for (Integer id : NovelIds) {
            bloomFilterUtil.add("novel"+ id);
        }
        List<Integer> chapterIds = chapterService.listAllIds();
        for (Integer id : chapterIds) {
            bloomFilterUtil.add("chapter"+ id);
        }
        bloomFilterUtil.add("novel"+null);
        bloomFilterUtil.add("chapter"+null);

    }
}
